import {defineStore} from "pinia";

export const useUserStore = defineStore('user', () => {
    const userInfo = ref(undefined)

    const isUserInitialized = computed(() => !!userInfo.value && !!userInfo.value.id)
    const roleList = computed(() => isUserInitialized.value ? userInfo.roleList : [])
    const permissionList = computed(() => userInfo.value?.permissionList || [])

    function setUserInfo(info) {
        userInfo.value = info
    }

    return {
        userInfo,
        roleList,
        permissionList,
        isUserInitialized,
        setUserInfo
    }
})